import socket
import fcntl
import struct
import sys
from netaddr import *

# Very simple python script to generate a target list using the subnet info from the specified interface

def get_ip_address(ifname):
    # SIOCGIFADDR = 0x8915
    return get_device_info(ifname, 0x8915)


def get_netmask(ifname):
    # SIOCGIFNETMASK = 0x891b
    return get_device_info(ifname, 0x891b)

def get_device_info(ifname, attr):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(
	fcntl.ioctl(
	s.fileno(),
	attr,
	struct.pack('256s', ifname[:15])
	)[20:24])

interface=bytes(sys.argv[1], 'iso-8859-1')

local_ip = get_ip_address(interface)
local_netmask = get_netmask(interface)

network = IPNetwork(local_ip + "/" + local_netmask)

for ip in network:
    print('%s' % ip)


